<?php

namespace App\Backend\Http\Controllers;

use App\Order;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;

class OrderController extends Controller
{
    /**
     * Display a listing of the resource.
     * @return Response
     */
    public function index(Request $request)
    {
        $where[] = ['id','>',0];
        if(!empty($request->status)){
            $where['status'] = $request->status;
        }
        if(isset($request->type)){
            $where['type'] = $request->type;
        }
        $data = $request->all();
        if($request->name || $request ->mobile){
            unset($where['status']);
            $where['user_id'] = User::where($data)->value('id');
        }
        if (!empty($request->date)) {
            $date = explode(' - ', $request->date);
            $data['orders'] = Order::where($where)->whereBetween('created_at',[$date[0],$date[1]])->orderBy('id', 'desc')->paginate(20);
        } else {
            $data['orders'] = Order::where($where)->orderBy('created_at', 'desc')->paginate(20);
        }
        return view('backend::order.list',$data);
    }

    /**
     * Show the form for creating a new resource.
     * @return Response
     */
    public function create()
    {
        return view('backend::create');
    }

    /**
     * Store a newly created resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function store(Request $request)
    {
    }

    /**
     * Show the specified resource.
     * @return Response
     */
    public function show()
    {
        return view('backend::show');
    }

    /**
     * Show the form for editing the specified resource.
     * @return Response
     */
    public function edit()
    {
        return view('backend::edit');
    }

    /**
     * Update the specified resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function update(Request $request)
    {
    }

    /**
     * Remove the specified resource from storage.
     * @return Response
     */
    public function destroy()
    {
    }
}
